package org.game.db.bean;

import org.game.db.cache.PlayerStoreCache;
import com.sojoys.artifact.factory.bytebuff.IByteBuff;
import static org.game.db.StaticResource.PlayerStoreResource.*;
import org.apache.commons.lang3.ArrayUtils;
import com.sojoys.artifact.build.data.base.BasePojo;
import java.util.List;
import java.sql.SQLException;
import com.sojoys.artifact.tools.ToolMap;
import com.sojoys.artifact.tools.SK_Plus;
import com.sojoys.artifact.tools.ToolCopy;
import org.game.db.cache.PlayerCache;
import java.sql.ResultSet;
import java.util.Map;
import com.alibaba.fastjson.JSONObject;
import com.sojoys.artifact.constant.DataModelKeyEnum;
import static org.game.db.StaticResource.PlayerStoreResource.*;
/**
 * 玩家商城
 */
public class PlayerStore extends BasePojo<PlayerStore> {
	
	
	/**
	 * 索引值
	 */
	private String[] indexValues = new String[2];
	
	/**
	* id
	*/
	private long id;
	
	/**
	* create_date
	*/
	private java.util.Date createDate;
	
	/**
	* modified_date
	*/
	private java.util.Date modifiedDate;
	
	/**
	* 玩家ID
	*/
	private int playerId;
	
	/**
	* 商店类型
	*/
	private int storeId;
	
	/**
	* 商品列表
	*/
	private List commodityIdList;
	
	/**
	* 今日刷新次数
	*/
	private int todayRefreshCount;
	
	/**
	* 总刷新次数
	*/
	private int totalRefreshCount;
	
	/**
	* 最后刷新时间
	*/
	private java.util.Date lastAutoRefreshTime;
	
	
	@Deprecated
	public static PlayerStore builder() {
		PlayerStore playerStore = new PlayerStore();
		return playerStore;
	}
	
	@Deprecated
	public PlayerStore() {
		super();
	}
	
	public PlayerStore(long id, int playerId, int storeId, List commodityIdList, int todayRefreshCount, int totalRefreshCount, java.util.Date lastAutoRefreshTime) {
		super();
		this.id = id;
		this.createDate = new java.util.Date();
		this.modifiedDate = new java.util.Date();
		this.playerId = playerId;
		this.storeId = storeId;
		this.commodityIdList = commodityIdList;
		this.todayRefreshCount = todayRefreshCount;
		this.totalRefreshCount = totalRefreshCount;
		this.lastAutoRefreshTime = lastAutoRefreshTime;
	}
	
	/**
	 * id
	 */
	public long getId() {return id;}
	
	/**
	 * id
	 */
	public PlayerStore setId(long id) {this.id = id;return this;}
	
	/**
	 * create_date
	 */
	public java.util.Date getCreateDate() {return createDate;}
	
	/**
	 * create_date
	 */
	protected PlayerStore setCreateDate(java.util.Date createDate) {this.createDate = createDate;return this;}
	
	/**
	 * modified_date
	 */
	public java.util.Date getModifiedDate() {return modifiedDate;}
	
	/**
	 * modified_date
	 */
	protected PlayerStore setModifiedDate(java.util.Date modifiedDate) {this.modifiedDate = modifiedDate;return this;}
	
	/**
	 * 玩家ID
	 */
	public int getPlayerId() {return playerId;}
	
	/**
	 * 玩家ID
	 */
	public PlayerStore setPlayerId(int playerId) {this.playerId = playerId;return this;}
	
	/**
	 * 商店类型
	 */
	public int getStoreId() {return storeId;}
	
	/**
	 * 商店类型
	 */
	public PlayerStore setStoreId(int storeId) {this.storeId = storeId;return this;}
	
	/**
	 * 商品列表
	 */
	public List getCommodityIdList() {return commodityIdList;}
	
	/**
	 * 商品列表
	 */
	public PlayerStore setCommodityIdList(List commodityIdList) {this.commodityIdList = commodityIdList;return this;}
	
	/**
	 * 商品列表
	 */
	public byte[] getCommodityIdListByte() {
		return toBytes(commodityIdList);
	}
	
	/**
	 * 商品列表
	 */
	public List initCommodityIdListByte(byte[] _byte) {
		return (List)forBytesObject(_byte);
	}	
	/**
	 * 今日刷新次数
	 */
	public int getTodayRefreshCount() {return todayRefreshCount;}
	
	/**
	 * 今日刷新次数
	 */
	public PlayerStore setTodayRefreshCount(int todayRefreshCount) {this.todayRefreshCount = todayRefreshCount;return this;}
	
	/**
	 * 总刷新次数
	 */
	public int getTotalRefreshCount() {return totalRefreshCount;}
	
	/**
	 * 总刷新次数
	 */
	public PlayerStore setTotalRefreshCount(int totalRefreshCount) {this.totalRefreshCount = totalRefreshCount;return this;}
	
	/**
	 * 最后刷新时间
	 */
	public java.util.Date getLastAutoRefreshTime() {return lastAutoRefreshTime;}
	
	/**
	 * 最后刷新时间
	 */
	public PlayerStore setLastAutoRefreshTime(java.util.Date lastAutoRefreshTime) {this.lastAutoRefreshTime = lastAutoRefreshTime;return this;}
	
	
	// 代理
	
	protected Object[] getColumnNames(DataModelKeyEnum e){
		switch (e) {
		case SOURCE:
			return SOURCE_COLUMN_NAMES;
		case PINGYING:
			return PINGYING_COLUMN_NAMES;
		case HASHCODE:
			return HASHCODE_COLUMN_NAMES;
		case REMARKS:
			return SOURCE_COLUMN_REMARKS;
		default:
			return PINGYING_COLUMN_NAMES;
		}
	}
	
	protected Object[] getFKTableNames(DataModelKeyEnum e){
		switch (e) {
		case SOURCE:
			return FK_SOURCE_TABLE_NAMES;
		case PINGYING:
			return FK_PINGYING_TABLE_NAMES;
		case HASHCODE:
			return FK_HASHCODE_TABLE_NAMES;
		default:
			return FK_PINGYING_TABLE_NAMES;
		}
	}
	
	protected Object[] getFKColumnNames(DataModelKeyEnum e){
		switch (e) {
		case SOURCE:
			return FK_SOURCE_COLUMN_NAMES;
		case PINGYING:
			return FK_PINGYING_COLUMN_NAMES;
		case HASHCODE:
			return FK_HASHCODE_COLUMN_NAMES;
		default:
			return FK_PINGYING_TABLE_NAMES;
		}
	}
	
	protected String[] getBasicTypes(){
		return COLUMN_BASICTYPES;
	}
	
	protected Class[] getClassTypes(){
		return COLUMN_CLASSTYPES;
	}
	
	protected String[] getColumnTypes(){
		return COLUMN_COLUMNTYPES;
	}
	
	protected int getColumnCount(){
		return COLUMN_COUNT;
	}
	
	protected Object[] getColumeValues(){
		Object[] values = new Object[COLUMN_COUNT];
        values[0] = this.id;
        values[1] = this.createDate;
        values[2] = this.modifiedDate;
        values[3] = this.playerId;
        values[4] = this.storeId;
        values[5] = this.commodityIdList;
        values[6] = this.todayRefreshCount;
        values[7] = this.totalRefreshCount;
        values[8] = this.lastAutoRefreshTime;
        return values;
	}
	
	public PlayerStore deepCopy(){
		PlayerStore playerStore = null;
		try {
			playerStore = (PlayerStore) super.clone();
		    playerStore.setCreateDate(ToolCopy.copyObject(this.createDate));
		    playerStore.setModifiedDate(ToolCopy.copyObject(this.modifiedDate));
		    playerStore.setCommodityIdList(ToolCopy.copyObject(this.commodityIdList));
		    playerStore.setLastAutoRefreshTime(ToolCopy.copyObject(this.lastAutoRefreshTime));
		    // 克隆索引
		    playerStore.indexValues = ArrayUtils.clone(indexValues);
			return playerStore;
		} catch (CloneNotSupportedException e) {
			e.printStackTrace();
		}
		return playerStore;
	}
	
	
	protected Map<Object, Object> toMap(Object[] keys,Map<Object, Object> map){
        map.put(keys[0], this.id);
        map.put(keys[1], this.createDate);
        map.put(keys[2], this.modifiedDate);
        map.put(keys[3], this.playerId);
        map.put(keys[4], this.storeId);
        map.put(keys[5], this.commodityIdList);
        map.put(keys[6], this.todayRefreshCount);
        map.put(keys[7], this.totalRefreshCount);
        map.put(keys[8], this.lastAutoRefreshTime);
        return map;
    }
    
    protected PlayerStore createForMap(Object[] keys,Map map){
   		this.id = (long)map.get(keys[0]);
   		this.createDate = (java.util.Date)map.get(keys[1]);
   		this.modifiedDate = (java.util.Date)map.get(keys[2]);
   		this.playerId = (int)map.get(keys[3]);
   		this.storeId = (int)map.get(keys[4]);
   		this.commodityIdList = (List)map.get(keys[5]);
   		this.todayRefreshCount = (int)map.get(keys[6]);
   		this.totalRefreshCount = (int)map.get(keys[7]);
   		this.lastAutoRefreshTime = (java.util.Date)map.get(keys[8]);
        return this;
    }
	
	
	protected JSONObject toJSONObject(Object[] keys,JSONObject obj){
        obj.put(keys[0], this.id);
        obj.put(keys[1], this.createDate);
        obj.put(keys[2], this.modifiedDate);
        obj.put(keys[3], this.playerId);
        obj.put(keys[4], this.storeId);
        obj.put(keys[5], toBytes(commodityIdList));
        obj.put(keys[6], this.todayRefreshCount);
        obj.put(keys[7], this.totalRefreshCount);
        obj.put(keys[8], this.lastAutoRefreshTime);
        return obj;
    }
    
    protected PlayerStore createForJSONObject(Object[] keys,JSONObject obj){
	    this.id = obj.getLongValue(keys[0]);
	    this.createDate = obj.getDate(keys[1]);
	    this.modifiedDate = obj.getDate(keys[2]);
	    this.playerId = obj.getIntValue(keys[3]);
	    this.storeId = obj.getIntValue(keys[4]);
		this.commodityIdList = (List)forBytesObject(obj.getBytes(keys[5]));
	    this.todayRefreshCount = obj.getIntValue(keys[6]);
	    this.totalRefreshCount = obj.getIntValue(keys[7]);
	    this.lastAutoRefreshTime = obj.getDate(keys[8]);
        return this;
    }
    
    
    public PlayerStore createForResultSet(ResultSet rs) throws SQLException{
	    this.id = rs.getLong(SOURCE_COLUMN_NAMES[0]);
	    this.createDate = rs.getTimestamp(SOURCE_COLUMN_NAMES[1]);
	    this.modifiedDate = rs.getTimestamp(SOURCE_COLUMN_NAMES[2]);
	    this.playerId = rs.getInt(SOURCE_COLUMN_NAMES[3]);
	    this.storeId = rs.getInt(SOURCE_COLUMN_NAMES[4]);
		this.commodityIdList = (List)forBytesObject(rs.getBytes(SOURCE_COLUMN_NAMES[5]));
	    this.todayRefreshCount = rs.getInt(SOURCE_COLUMN_NAMES[6]);
	    this.totalRefreshCount = rs.getInt(SOURCE_COLUMN_NAMES[7]);
	    this.lastAutoRefreshTime = rs.getTimestamp(SOURCE_COLUMN_NAMES[8]);
	    return this;
    }
    
    protected void writeBytes(IByteBuff byteBuf){
	    byteBuf.writeLong(this.id);
	    byteBuf.writeDate(this.createDate);
	    byteBuf.writeDate(this.modifiedDate);
	    byteBuf.writeInt(this.playerId);
	    byteBuf.writeInt(this.storeId);
	    byteBuf.writeObject(this.commodityIdList);
	    byteBuf.writeInt(this.todayRefreshCount);
	    byteBuf.writeInt(this.totalRefreshCount);
	    byteBuf.writeDate(this.lastAutoRefreshTime);
    }
	
	protected PlayerStore readBytes(IByteBuff byteBuf){
	    this.id = byteBuf.readLong(null);
	    this.createDate = byteBuf.readDate(null);
	    this.modifiedDate = byteBuf.readDate(null);
	    this.playerId = byteBuf.readInt(null);
	    this.storeId = byteBuf.readInt(null);
	    this.commodityIdList = (List)byteBuf.readObject();
	    this.todayRefreshCount = byteBuf.readInt(null);
	    this.totalRefreshCount = byteBuf.readInt(null);
	    this.lastAutoRefreshTime = byteBuf.readDate(null);
	    return this;
	}
    
    
    protected JSONObject exportFKTableMap(Object[] keys,JSONObject map,DataModelKeyEnum e){
        return map;
    }
    
    protected boolean importFKTableMap(Object[] keys,JSONObject map,DataModelKeyEnum e){
		return true;
    }
    
	/** 取得[player]*/
	public Player getPlayerPkPlayerId(){
		return PlayerCache.me().getById(playerId);
	}
	
    /** 级联删除(延迟入库) */
    public boolean deleteAndSon(){
    	return false;
    }
    
    /** 级联删除(及时入库) */
    public boolean deleteAndSonAndFlush(){
    	return false;
    }
    
    /** 延迟插入数据库 */
    public PlayerStore insert(){
    	return PlayerStoreCache.me().insert(this);
    }
    /** 延迟更新数据库 */
    public PlayerStore update(){
    	return PlayerStoreCache.me().update(this);
    }
    /** 延迟删除数据库 */
    public boolean delete(){
    	return PlayerStoreCache.me().delete(this);
    }
    /** 即时插入数据库 */
    public PlayerStore insertAndFlush(){
    	return PlayerStoreCache.me().insertAndFlush(this);
    }
    /** 即时更新数据库 */
    public PlayerStore updateAndFlush(){
    	return PlayerStoreCache.me().updateAndFlush(this);
    }
    /** 即时删除数据库 */
    public boolean deleteAndFlush(){
    	return PlayerStoreCache.me().deleteAndFlush(this);
    }
    
    
	
	/**
	 * 同步索引值
	 */
	public PlayerStore syncIndexValues(){
		indexValues[0] = SK_Plus.b(getId()).e();
		indexValues[1] = SK_Plus.b(getPlayerId()).e();
		return this;
	}
	/**
	 * 取得索引
	 */
	public String[] getIndexValues(){
		return indexValues;
	}
	
	protected Object getPrimaryKey(){
		return getId();
	}
	
	protected void setPrimaryKey(Object key){
		setId((long)key);
	}
//自定义内容起始位置
//自定义内容结束位置
}